package com.manager.controller;

import com.manager.bean.Repair;
import com.manager.service.RepairService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

import com.manager.bean.PageInfo;

/**
 * (Repair)表控制层
 *
 * @author makejava
 * @since 2021-03-02 20:15:30
 */
@Controller
public class RepairController {
    /**
     * 服务对象
     **/
    @Resource
    private RepairService repairService;

    @RequestMapping(value = "/findRepair")
    public String findRepair(Model model,Integer DormitoryId, Integer StudentId, Integer pageIndex, Integer pageSize) {
        PageInfo<Repair> pi = repairService.findPageInfo(DormitoryId,StudentId,pageIndex,pageSize);
        model.addAttribute("pi", pi);
        return "repair_list";
    }


    @RequestMapping(value = "/exportRepairlist", method = RequestMethod.POST)
    @ResponseBody
    public List<Repair> exportRepair() {
        List<Repair> repairList = repairService.getAll();
        return repairList;
    }


    @RequestMapping("/deleteRepair")
    @ResponseBody
    public String deleteRepair(Integer Id) {
        repairService.deleteById(Id);
        return "repair_list";
    }


    @RequestMapping(value = "/addRepair", method = RequestMethod.POST)
    @ResponseBody
    public String addRepair(@RequestBody Repair repair) {
        repairService.insert(repair);
        return "repair_list";
    }


    @RequestMapping(value = "/updateRepair", method = RequestMethod.POST)
    public String updateRepair(Repair repair) {
        repairService.update(repair);
        return "redirect:/findRepair";
    }


    @RequestMapping("/findRepairById")
    public String findRepairById(Integer Id, HttpSession session, Model model) {
        Repair s = repairService.queryById(Id);
        session.setAttribute("s", s);
        model.addAttribute("s", s);
        return "repair_edit";
    }

}
